import sys

sys.path.append('rueckenwind')
import rw

address = '127.0.0.1'
port = 8000
if '--public' in sys.argv:
    address = '0.0.0.0'
    if len(sys.argv) > 2:
        port = int(sys.argv[2])
else:
    rw.DEBUG = True


# if linux...

try:
    import commands
    for line in commands.getoutput("/sbin/ifconfig").split('\n'):
        if 'inet ' in line and not '127.0.0.1' in line:
            ip = line.split('inet ', 1)[1].split(' ')[0]
except:
    ip = '127.0.0.1'

try:
    import qrcode
    if ip:
        image = qrcode.make(ip + ';' + str(port))
        image.save('fullsteam/static/ip.png')

    # qr codes

    image = qrcode.make('http://www.leijuna.de/static/leijunaweb/fullsteam.apk')
    image.save('fullsteam/static/download.png')
except:
    print 'no qrcodes :('
    open('fullsteam/static/ip.png', 'w')
    open('fullsteam/static/download.png', 'w')



rw.start('fullsteam', port=port, address=address)

